<?php

namespace app\service\admin\projects\video;

use app\model\Common;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class ClassifyService
{
    /**
     * 获取列表
     * User : Du
     * Date : 2023/2/9
     * Time : 15:42
     * @param array $request
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getList(array $request): array
    {
        $page = $request['page'] ?? 0;
        $pageSize = $request['size'] ?? 10;
        $so = $request['so'] ?? '';
        $filter = [];
        if ($so) {
            $filter[] = ['name', 'like', '%' . $so . '%'];;
        }
        $field = ['id', 'name', 'create_time'];
        return Common::getList(VideoClassifyTable, $filter, $field, $page, $pageSize);
    }

    /**
     * 添加
     * User : Du
     * Date : 2023/2/9
     * Time : 16:23
     * @param array $request
     * @return false|int|string
     */
    public static function addData(array $request)
    {
        if (!isset($request['name']) || !$request['name']) {
            return false;
        }
        return Common::addData(VideoClassifyTable, $request);
    }

    /**
     * 删除
     * User : Du
     * Date : 2023/2/9
     * Time : 16:28
     * @param array $request
     * @return false|int|string
     * @throws DbException
     */
    public static function delData(array $request)
    {
        if (isset($request['id']) || !$request['id']) {
            return false;
        }
        return Common::deleteData(VideoClassifyTable, ['id' => $request['id']]);
    }
}
